package edu.biwu.mapper;

import edu.biwu.po.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface UserMapper {

    @Select("SELECT id,username,birthday,gender,address FROM mybatis02.user WHERE id = #{id}")
    User findUserById(int id);

    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(property = "orders",javaType = List.class,column = "id",
            many=@Many(select = "edu.biwu.mapper.OrderMapper.findByUserId",fetchType = FetchType.LAZY))
    })
    @Select("SELECT id,username,birthday,gender,address FROM mybatis02.user")
    List<User> findAllLazy();
}
